package edu.njust.cma.service.impl;

import edu.njust.cma.config.TimeConfig;
import edu.njust.cma.mapper.QualityMapper;
import edu.njust.cma.mapper.SmallProjectMapper;
import edu.njust.cma.mapper.StandardMethodMapper;
import edu.njust.cma.mapper.TaskMapper;
import edu.njust.cma.pojo.Project;
import edu.njust.cma.pojo.StandardMethod;
import edu.njust.cma.service.QualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationAotProcessor;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

@Service
public class QualityServiceImpl implements QualityService {
    @Autowired
    QualityMapper qualityMapper;
    @Autowired
    TaskMapper taskMapper;
    @Autowired
    SmallProjectMapper smallProjectMapper;
    @Autowired
    StandardMethodMapper standardMethodMapper;
    //1. 创建检测项目
    @Override
    public void createProject(Project project, List<Integer> project_standerIds, Integer authorizerId) {
        String nowTime = TimeConfig.getNowTime();
        project.setCreationTime(nowTime);
        project.setQualityDirectorId(authorizerId);
        //创建项目
        qualityMapper.createPro(project);
        Integer projectId = qualityMapper.getLastProjectId();

        //创建小项目
        for(int standerId : project_standerIds){
           smallProjectMapper.addSmallProject(projectId,standerId);
        }
        //创建任务
        for(int standerId : project_standerIds){
            List<StandardMethod> standardMethods = standardMethodMapper.findById(standerId);
            int smallProjectId = smallProjectMapper.findIdByProjectIdAndStandardId(projectId,standerId);
            for(StandardMethod standardMethod : standardMethods){
                taskMapper.addTask(smallProjectId,standardMethod.getId(),standardMethod.getMethodName(),nowTime);
            }
        }
    }

}
